package test00.lx08;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @author CSY
 * @date 2025 - 04 - 08
 */
public class MainTest {
    public static void main(String[] args) {
        List<String> name1 = Arrays.asList("张盛大","李四","李二牛", "赵六", "王师傅", "李清照","李世明");
        List<String> name2 = Arrays.asList("张盛大","张三","张方浩","赵六","王师傅","张三丰","李世明","张大米");

        //Stream.collect(Collectors.toList());返回的集合是可变的 - 可以使用add()和remove()
        //Stream.toList();返回的集合是不可变的 - 不可以使用add()和remove()
        Stream<String> stream1 = name1.stream();
        List<String> collectStus1 = stream1.filter((t) -> t.length() == 3)
                .limit(3)
                .collect(Collectors.toList());
        Stream<String> stream2 = name2.stream();
        List<String> collectStus2 = stream2.filter((t) -> t.charAt(0) == '张')
                .skip(2)
                .collect(Collectors.toList());
        List<String> allStus = new ArrayList<>(collectStus1);
        allStus.addAll(collectStus2);
        List<Student> lastStus = allStus.stream().map((t) -> {
            Student s = new Student();
            s.setName(t);
            return s;
        }).collect(Collectors.toList());
        lastStus.forEach(System.out::println);

    }
}
